home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / ServiceMail / src / services / dis.tcl < prev    next >
Encoding:
Text File  |  1993-05-07  |  2.1 KB  |  73 lines

  1. # dis
  2. #
  3. # 30-June-92 jay@eitech.com
  4. #
  5. # This service will access DIS, the Distributed Information Service.
  6. # The input is the language-independent version of DIS, e.g. (object? foo)
  7. # one command per line and the results will be returned in a similar fashion
  8. # The answers can either be 1) separate, in which case the response is a
  9. # multipart message where the first part are the results and the
  10. # second part is the corresponding commands; or 2) interspersed, in
  11. # which case the resulting message alternates commands with the results
  12.  
  13. proc dodis { switches envelope inputs } {
  14.  
  15. #    if { ! [local [getfield $envelope FROM]] } {
  16. #        setfield response STRING "Sorry, this service is only provided for local users"
  17. #        return [mailout [turnaround $envelope] $response]
  18. #    }
  19.  
  20.     ## where the commands are
  21.     set src [getfield $inputs FILE]
  22.  
  23.     set interspersed 1
  24.     set server default
  25.     set port default
  26.  
  27.     if { [llength $switches] != 0 } {
  28.     if { [lsearch $switches separate] >= 0 } {
  29.         set interspersed 0
  30.     }
  31.     if { [set i [lsearch $switches server]] >= 0 } {
  32.         set server [lindex $switches [expr $i+1]]
  33.     }
  34.     if { [set i [lsearch $switches port]] >= 0 } {
  35.         set port [lindex $switches [expr $i+1]]
  36.     }
  37.     }
  38.  
  39.     catch "exec smdis $src -i $interspersed -s $server -p $port > $src.out"
  40.     # for testing
  41.     #    set fid [open $src.out w]
  42.     #    puts $fid "This service isn't really operational yet"
  43.  
  44.     #    puts $fid "interspersed is " nonewline
  45.     #    puts $fid $interspersed
  46.     #    puts $fid " server is " nonewline
  47.     #    puts $fid $server
  48.     #    puts $fid " port is " nonewline
  49.     #    puts $fid $port
  50.     #    close $fid
  51.  
  52.     if { $interspersed } {
  53.     setfield output TYPE application
  54.     setfield output SUBTYPE DIS
  55.     setfield output FILE $src.out
  56.     setfield output DESCRIPTION "DIS results"
  57.     } else {
  58.     setfield part1 TYPE application
  59.     setfield part1 SUBTYPE DIS
  60.     setfield part1 FILE $src.out
  61.     setfield part1 DESCRIPTION "DIS results"
  62.  
  63.     setfield part2 FILE $src
  64.     setfield part2 DESCRIPTION "original input"
  65.  
  66.     setfield output TYPE multipart
  67.         setfield output SUBTYPE mixed
  68.         setfield output PARTS [list $part1 $part2]
  69.     }
  70.  
  71.     return [mailout [turnaround $envelope] $output]
  72. }
  73.